package org.come.control.festival;

import org.come.Frame.ZhuFrame;
import org.come.until.GoodsListFromServerUntil;
import com.tool.image.ImageMixDeal;
import org.come.until.GsonUtil;
import org.come.entity.Goodstable;
import org.come.action.FromServerAction;

public class GiveGoodsControl implements FromServerAction
{
    @Override
    public void controlMessFromServer(final String mes, final String type) {
        final Goodstable goodstable = (Goodstable)GsonUtil.getGsonUtil().getgson().fromJson(mes, Goodstable.class);
        if (goodstable.getRole_id().compareTo(ImageMixDeal.userimg.getRoleShow().getRole_id()) != 0) {
            return;
        }
        final int sum = GoodsListFromServerUntil.Surplussum((goodstable != null) ? (goodstable.getType() + "") : "6500", goodstable.getGoodsid().toString(), 1);
        if (sum > 0) {
            if (goodstable.getUsetime() == null) {
                goodstable.setUsetime(Integer.valueOf(1));
            }
            goodstable.setStatus(Integer.valueOf(0));
            GoodsListFromServerUntil.addGood(goodstable);
            ZhuFrame.getZhuJpanel().addPrompt2("元旦孵蛋成功，恭喜你获得" + goodstable.getGoodsname() + "！！！");
        }
        else {
            ZhuFrame.getZhuJpanel().addPrompt2("背包不足，自动丢弃" + goodstable.getGoodsname() + "！！！");
        }
    }
}
